CC = g++
AR = ar

DEFINES := -D_UNIX -D_LINUX
CFLAGS := -fPIC -Wall -g -O3
LDFLAGS := 
INC_PATH := -I../include/

DLL_EXPORT_FILE := SilmLog.ldef

STATIC_LIBS +=
STATIC_LIB_PATH +=
LIBS += 
LIB_PATH +=

sources := SilmLog.cpp SilmLogApi.cpp SilmLogUtil.cpp

isEmpty := $(shell cat /etc/system-release 2>/dev/null | grep -i centos)
ifneq ($(isEmpty), )
CFLAGS += -DCENTOS
endif

isEmpty := $(shell cat /etc/system-release 2>/dev/null | grep -i redhat)
ifneq ($(isEmpty), )
CFLAGS += -DREDHAT
endif

isEmpty := $(shell lsb_release -i 2>/dev/null | grep -i ubuntu)
ifneq ($(isEmpty), )
CFLAGS += -DUBUNTU
endif

PWD := $(shell pwd)

__midobjs := $(patsubst %.c, %.o, $(sources))
__midobjs := $(patsubst %.cc, %.o, $(__midobjs))
objects := $(patsubst %.cpp, %.o, $(__midobjs))

goal: libsilmlog.a libsilmlog.so
	@echo "make done"

libsilmlog.a : $(objects)
	$(AR) rcs $@ $^

libsilmlog.so : $(objects)
	$(CC) $(LDFLAGS) -shared -Wl,--version-script=$(DLL_EXPORT_FILE)  $^ -Wl,-Bstatic $(STATIC_LIBS) $(STATIC_LIB_PATH) -Wl,-Bdynamic $(LIBS) $(LIB_PATH) -o $@

%.o : %.c
	$(CC) $(CFLAGS) $(DEFINES) $(INC_PATH) -c $< -o $@

%.o : %.cc
	$(CC) $(CFLAGS) $(DEFINES) $(INC_PATH) -c $< -o $@
	
%.o : %.cpp
	$(CC) $(CFLAGS) $(DEFINES) $(INC_PATH) -c $< -o $@

.PHONY : clean
clean :
	@echo "clean..."
	-rm -rf *.o libsilmlog.a libsilmlog.so
